package com.yugao.fintech.antelope.base.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.concurrent.TimeUnit;

@Configuration
public class CaffeineConfig {

    @Bean
    @Primary
    public Cache<String, Object> caffeineCache() {
        return Caffeine.newBuilder().recordStats()
                // 设置最后一次写入或访问后经过固定时间过期
                .expireAfterWrite(10, TimeUnit.SECONDS)
                // 初始的缓存空间大小
                .maximumSize(100)
                .build();
    }
}
